package com.demo.service_admin.impl;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Join;
import javax.persistence.criteria.JoinType;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;
import javax.transaction.Transactional;

import org.apache.commons.lang3.StringUtils;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;

import com.demo.dao_admin.LecturerDAO;
import com.demo.entity.Course;
import com.demo.entity.Department;
import com.demo.entity.LecturerData;
import com.demo.service_admin.LecturerService;

@Service("adminLecturerService")
@Transactional
public class LecturerServiceImpl implements LecturerService {

	@Resource(name = "adminLecturerDAO")
	LecturerDAO courseSectionDAO;

	@Override
	public Page<LecturerData> findAll(LecturerData lecturerData, Pageable pageable) {
		

		Specification<LecturerData> spec = new Specification<LecturerData>() {
			private static final long serialVersionUID = 1L;

			@Override
			public Predicate toPredicate(Root<LecturerData> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
				//Please tell me：下面会翻译成什么sql
				//两张表的内联或者做外联查询
				// from 章节表 inner join 课程表 where 课程表.id=?1 and 章节表.chapter=?2
				Join<LecturerData, Department> join = root.join("dep", JoinType.LEFT);// A left outer join B 不等于 B left outer join A
				
				List<Predicate> predicates = new ArrayList<>();
				
				
				return cb.and(predicates.toArray(new Predicate[predicates.size()]));// 把所有查询条件用and拼接
				
			}
		};

		Page<LecturerData> list = courseSectionDAO.findAll(pageable);
		return list;
	}

	@Override
	public LecturerData findById(Long id) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public int batchDelete(Long[] ids) {
		// TODO Auto-generated method stub
		return 0;
	}

	
}